#include "stdafx.h"
#include "Clock.h"


Clock::Clock(void)
{
	SetTimer(0, 1000, NULL);
	//_label.SetParent(this);
}


Clock::~Clock(void)
{
}


void Clock::Serialize(CArchive& ar)
{
	Graphic::Serialize(ar);
	_label.Serialize(ar);

	if (ar.IsStoring())
	{	// storing code
	}
	else
	{	// loading code
		CPoint topLeft = _label.getWindowTopLeft();
		initPos(topLeft, topLeft);
	}
}

BEGIN_MESSAGE_MAP(Clock, Graphic)
	ON_WM_TIMER()
END_MESSAGE_MAP()


void Clock::OnTimer(UINT_PTR nIDEvent)
{
	getTime();
	_label.Invalidate();

	Graphic::OnTimer(nIDEvent);
}

void Clock::initPos(CPoint& pt1, CPoint& pt2)
{
	const CString str(L"2000-12-31 15:34:58");
	CSize timeSz = getTextSize(str, &_label._font);
	CRect wndRect(pt1, pt1 + timeSz);

	_label.MoveWindow(wndRect);

	getTime();
}

void Clock::getTime(void)
{
	CTime tm = CTime::GetCurrentTime();
	_label._text = tm.Format("%Y-%m-%d %H:%M:%S");
}
